import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/login"
  },
  {
    path: '/login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/home',
    component: () => import('../views/HomeView.vue'),
    children:[
      {
        path: '/',
        redirect: "/home/not"
      },
      {  path:'constitutiontype',component: () => import('../views/ConstitutiontypeView.vue')
    },
      {  path:'archives',component: () => import('../views/ArchivesView.vue')
    },
      { path:'evaluation',component: () => import('../views/EvaluationView.vue')
    },
    {   path:'consulting',component: () => import('../views/ConsultingView.vue')
  },
    {   path:'health',component: () => import('../views/HealthView.vue')

  },
  {      path:'report',component: () => import('../views/ReportView.vue')

  },
    {       path:'not',component: () => import('../views/NotView.vue')

  },
  {  path:'book',component: () => import('../views/BookingView.vue')// 允许通过props接收路由参数

  },
    {            path:'make',component: () => import('../views/MakeView.vue')
  },
  {            path:'questionnaire',component: () => import('../views/QuestionnaireView.vue')
},
{            path:'suggestions',component: () => import('../views/SuggestionsView.vue')
},
    ]
  },
  {
    path: '/login',
    component: () => import('../views/LoginView.vue')
  },

  {
    path: '/index',
    component: () => import('../views/IndexView.vue'),
    children:[
      { path: "empinfo", name: "empinfo", component: () => import("../components/EmpInfo.vue") },
      { path: "hello", name: "hello", component: () => import("../components/HelloWorld.vue") }
    ]
  },
]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//路由后置守卫
router.afterEach((to) => {
  let menpath = []
  //如果breadcrumbNames是空的，就不需要传递参数
  if (!to.query.menusText) {
    //调用veux中mutations中的方法
    router.app.$store.commit("getBreadcrumbNames")
  } else {
     //如果breadcrumbNames是不是空值
    if (to.query.menusText.length != 0) {
      //根据逗号分隔字符串
      menpath = to.query.menusText.split(",")
      //调用veux中mutations中的方法，并传递参数
      router.app.$store.commit("getBreadcrumbNames", menpath)
    } 
  }
})

export default router
